package ${packageName}.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.educate.common.web.R;
import ${packageName}.model.bo.${ModelName}BO;
import ${packageName}.rpc.api.${ModelName}Service;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("${modelName}")
public class ${ModelName}Controller {

    @Reference(version = "${r'${'}api.service.version}",
            application = "${r'${'}dubbo.application.id}",
            url = "${r'${'}dubbo.application.url}")
    private ${ModelName}Service ${modelName}Service;

    @PostMapping(value = "/create")
    public R create(@RequestBody ${ModelName}BO bo) {
        ${modelName}Service.create(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete")
    public R delete(@RequestBody ${ModelName}BO bo) {
        ${modelName}Service.delete(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete/{${modelName}Id}")
    public R delete(@PathVariable String ${modelName}Id) {
        ${modelName}Service.delete(${modelName}Id);
        return R.ok();
    }

    @PostMapping(value = "/detail/{${modelName}Id}")
    public R<${ModelName}BO> detail(@PathVariable String ${modelName}Id) {
        ${ModelName}BO bo = ${modelName}Service.detail(${modelName}Id);
        return R.ok(bo);
    }

    @PostMapping(value = "/detail")
    public R<${ModelName}BO> detail(@RequestBody ${ModelName}BO bo) {
        ${ModelName}BO detail = ${modelName}Service.detail(bo);
        return R.ok(detail);
    }

    @PostMapping(value = "/update")
    public R<${ModelName}BO> update(@RequestBody ${ModelName}BO bo) {
        ${modelName}Service.update(bo);
        return R.ok();
    }

    @PostMapping(value = "/query")
    public R<Page<${ModelName}BO>> query(@RequestBody ${ModelName}BO bo) {
        Page<${ModelName}BO> result = ${modelName}Service.query(bo, bo.pageable());
        return R.ok(result);
    }

    @PostMapping(value = "/list")
    public R<List<${ModelName}BO>> list(@RequestBody ${ModelName}BO bo) {
        List<${ModelName}BO> result = ${modelName}Service.list(bo);
        return R.ok(result);
    }

}
